<?php
namespace app\portal\controller;
use cmf\controller\HomeBaseController;
use think\Cookie;
use think\Db;
use think\Request;


class GrzlController extends  HomeBaseController{
    public function grzl(Request $request){
        //判断表单是否提交
        if(isset($_POST['grzl'])){
            //获取表单提交数据
            $name=$_POST["name"];
            $sex=$_POST["sex"];
            $age=$_POST["age"];
            $education=$_POST["education"];
            $school_age=$_POST["school_age"];
            $city=$_POST["city"];
            //获取表单上传图片
            $file = request()->file('image');

            if($file){
                // 移动到upload images目录下
                $info=$file->move(CMF_ROOT.'public'.DS.'upload');
//                $lujing = $info -> getSaveName();
                if($info){
//                    $save_path="/upload/".DS.date('Ymd');
                    $save_path="\upload".DS.date('Ymd').DS;
//                    $save_path=CMF_ROOT.'public'.DS.'upload'.date('Ymd');
                    //$path=json(['code'=>1,'url'=>$save_path.$info->getFilename()]);
                    Db::name('teacher_picture')->insert(['picture_path'=>$save_path.$info->getFilename()]);
//                    // 输出 42a79759f284b767dfcb2a0197904287.jpg
//                    echo $info->getFilename();
                }else{

                    // 上传失败获取错误信息
                    echo $file->getError();
                }
            }


            $sql=Db::name('teacher')->insert(['name'=>$name,'sex'=>$sex,'age'=>$age,
                'education'=>$education,'school_age'=>$school_age,'city'=>$city]);
            if($sql){
                $this->success('保存成功!');
              // return $this->redirect('Grzl/grzl');
            }
        }


    }

    public function aa(){
 //        $res = Cookie::get('name','');
 //        $this->assign('name', $res[0]);
        //$id = $this->request->param('id', 0, 'intval');
//        if(isset($_POST['grzl'])){
//            $id = $this->request->param('id', 0, 'intval');
//        }
     $res=Db::name('teacher')->join('qq_teacher_picture','qq_teacher.id=qq_teacher_picture.teacher_id')
             ->where('qq_teacher.id',1)
              ->select();
    // dump(cmf_get_image_url($res[0]['picture_path']));
         $this->assign('item',$res[0]);
     return $this->fetch(':grzl');
    }

}
